import Cookies from "js-cookie";

const TokenKey = "ruifox_admin_token";
const routerKey = "ruifox_user_router";
const menuKey = "ruifox_user_menu";
const userInfoKey = "ruifox_user_info";
export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  return Cookies.set(TokenKey, token, { expires: 2 });
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function setRouter(routes) {
  routes = JSON.stringify(routes);
  return localStorage.setItem(routerKey, routes);
}

export function getRouter() {
  return JSON.parse(localStorage.getItem(routerKey));
}
export function setMenus(menus) {
  menus = JSON.stringify(menus);
  return localStorage.setItem(menuKey, menus);
}

export function getMenus() {
  return JSON.parse(localStorage.getItem(menuKey));
}

export function removeMenus() {
  return localStorage.removeItem(menuKey);
}

export function removeRouter() {
  return localStorage.removeItem(routerKey);
}
export function setLoginState(state) {
  return Cookies.set("ruifox_loginState", state, { expires: 2 });
}
export function getLoginState() {
  return Cookies.get("ruifox_loginState");
}
export function setUserInfo(info) {
  info = JSON.stringify(info);
  return localStorage.setItem(userInfoKey, info);
}
export function getUserInfo() {
  return JSON.parse(localStorage.getItem(userInfoKey));
}
export function setSiteInfo(info) {
  info = JSON.stringify(info);
  return localStorage.setItem("site_info", info);
}
export function getSiteInfo() {
  return JSON.parse(localStorage.getItem("site_info"));
}
export function setRefreshToken(token) {
  return Cookies.set('ruifox_refresh_token',token)
}
export function getRefreshToken() {
  return Cookies.get('ruifox_refresh_token')
}

export function setCurrentCat(category) {
  let _category = JSON.stringify(category);
  return localStorage.setItem("current_category", _category);
}

export function getCurrentCat() {
  return JSON.parse(localStorage.getItem("current_category"));
}
export function setUserCategories(categories) {
  let _categories = JSON.stringify(categories);
  return localStorage.setItem("user_categories", _categories);
}
export function getUserCategories() {
  return JSON.parse(localStorage.getItem("user_categories"));
}
export function setUserDepartCategories(categories) {
  let _categories = JSON.stringify(categories);
  return localStorage.setItem("user_categories_depart", _categories);
}
export function getUserDepartCategories() {
  return JSON.parse(localStorage.getItem("user_categories_depart"));
}
export function setUserCategoriesFlat(categories) {
  let _categories = JSON.stringify(categories);
  return localStorage.setItem("user_categories_flat", _categories);
}
export function getUserCategoriesFlat() {
  return JSON.parse(localStorage.getItem("user_categories_flat"));
}
export function setThemeColor(themeColor) {
  return localStorage.setItem("ruifox_admin_theme", themeColor);
}
export function getThemeColor() {
  return localStorage.getItem("ruifox_admin_theme");
}

export function setStorageDragIds(ids) {
  let _ids = JSON.stringify(ids);
  return localStorage.setItem("drag_ids", _ids);
}
export function getStorageDragIds() {
  return JSON.parse(localStorage.getItem("drag_ids"));
}
export function setCommonCategories(categories) {
  let _categories = JSON.stringify(categories);
  return localStorage.setItem("common_categories", _categories);
}
export function getCommonCategories() {
  return JSON.parse(localStorage.getItem("common_categories"));
}
export function setSiteGroup(sites) {
  let _sites = JSON.stringify(sites);
  return localStorage.setItem("ruifox_site_group", _sites);
}
export function getSiteGroup() {
  return JSON.parse(localStorage.getItem("ruifox_site_group"));
}
export function setCurrentSite(site) {
  site = JSON.stringify(site)
  return localStorage.setItem("ruifox_current_site", site);
}
export function getCurrentSite() {
  const site = localStorage.getItem("ruifox_current_site");
  if(!site || site == 'undefined'){
    return null
  }
  return JSON.parse(localStorage.getItem("ruifox_current_site"));
}
export function setArticleDragIds(ids) {
  let _ids = JSON.stringify(ids);
  return localStorage.setItem("article_drag_ids", _ids);
}
export function getArticleDragIds() {
  return JSON.parse(localStorage.getItem("article_drag_ids"));
}
export function setFormDesignInfo(formInfo) {
  let _formInfo = JSON.stringify(formInfo);
  return localStorage.setItem("formDesign_formInfo", _formInfo);
}
export function getFormDesignInfo() {
  return JSON.parse(localStorage.getItem("formDesign_formInfo"));
}
export function setCustomSetting(setting) {
  let _setting = JSON.stringify(setting);
  return localStorage.setItem("custom_setting", _setting);
}
export function getCustomSetting() {
  return JSON.parse(localStorage.getItem("custom_setting"));
}
export function setLocSaveId(id) {
  let _id = JSON.stringify(id);
  return localStorage.setItem("loc_save_id", _id);
}
export function getLocSaveId() {
  return JSON.parse(localStorage.getItem("loc_save_id"));
}
export function removeLocSaveId() {
  return localStorage.removeItem("loc_save_id");
}
export function setBtnsPermissonList(btnsPermissonList) {
  let _btnsPermissonList = JSON.stringify(btnsPermissonList);
  return localStorage.setItem(
    "formDesign_btnsPermissonList",
    _btnsPermissonList
  );
}
export function getBtnsPermissonList() {
  return JSON.parse(localStorage.getItem("formDesign_btnsPermissonList"));
}
export function setLocCategoryType(categoryType) {
  let _categoryType = JSON.stringify(categoryType);
  return localStorage.setItem("formDesign_categoryType", _categoryType);
}
export function getLocCategoryType() {
  return JSON.parse(localStorage.getItem("formDesign_categoryType"));
}
export function setLocCategoryModel(categoryModel) {
  let _categoryModel = JSON.stringify(categoryModel);
  return localStorage.setItem("formDesign_categoryModel", _categoryModel);
}
export function getLocCategoryModel() {
  return JSON.parse(localStorage.getItem("formDesign_categoryModel"));
}
export function setLocCanReleaseModel(canReleaseModel) {
  let _canReleaseModel = JSON.stringify(canReleaseModel);
  return localStorage.setItem("formDesign_canReleaseModel", _canReleaseModel);
}
export function getLocCanReleaseModel() {
  return JSON.parse(localStorage.getItem("formDesign_canReleaseModel"));
}
export function setLocDoctorBatchManage(doctorBatchList) {
  let _doctorBatchList = JSON.stringify(doctorBatchList);
  return localStorage.setItem("doctorEdit_doctorBatchList", _doctorBatchList);
}
export function getLocDoctorBatchManage() {
  return JSON.parse(localStorage.getItem("doctorEdit_doctorBatchList"));
}
